package my.edu.model.information.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import my.edu.common.validate.groups.Insert;
import my.edu.common.domain.Response;
import my.edu.model.information.entity.Route;
import my.edu.model.information.service.IRouteService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/info/route")
@RestController
@Tag(name = "线路接口")
@Validated
public class RouteController {
    @Autowired
    private IRouteService routeService;


    @PutMapping
    @RequiresPermissions("route:save")
    @Operation(summary = "新增线路")
    public Response save(@Validated(value = Insert.class) @RequestBody Route route) {
        route.setStatus(1);
        routeService.save(route);
        return Response.success();
    }

    @GetMapping
    @RequiresPermissions("route:get")
    @Operation(summary = "获取线路列表")
    public Response getRoute() {
        return Response.success(routeService.list());
    }

    @GetMapping("/{id}")
    @RequiresPermissions("route:get")
    @Operation(summary = "根据编号获取线路信息")
    public Response getRouteById(@PathVariable @NotBlank(message = "id不能为空") String id) {
        return Response.success(routeService.getById(id));
    }

    @PostMapping("/update")
    @RequiresPermissions("route:update")
    @Operation(summary = "更新线路信息")
    public Response update(@Valid @RequestBody Route route) {
        routeService.updateByDTO(route);
        return Response.success();
    }
}
